import {reqSearchInfo} from "@/api";

//定义一个actions -- 接收组件的动作
const actions ={
    //获取搜索数据
    async getSearchInfo({ commit},params){
        let result = await reqSearchInfo(params);
        if(result.code === 200){
            commit('SAVE_SEARCH_INFO',result.data)
            // console.log(result.data)

        }else{
            alert(result.message)
        }
    }
};
//定义一个mutations -- 真正修改数据
const mutations = {
    //获取搜索数据
    SAVE_SEARCH_INFO(state,info) {
        state.searchInfo = info;
    }
};

//定义一个state -- 存储数据
const state = {
 searchInfo: {}
};

//定义一个getters -- 对state中的数据的处理
const getters = {
    //往getters里面存储商品数据
    goodsList(state){
		return state.searchInfo.goodsList
	},
    attrsList(state){
		return state.searchInfo.attrsList
	},
    trademarkList(state){
		return state.searchInfo.trademarkList
	},
    total(){
        return state.searchInfo.total
    }
};

//暴露
export default {
    actions,
    mutations,
    state,
    getters,
}